﻿using System.Windows;
using System.Windows.Controls;
using CodeAngel.UI.Extensions;

namespace CodeAngel.UI
{
    /// <summary>
    /// Interaction logic for LabeledTextBox.xaml
    /// </summary>
    public partial class LabeledTextBox : UserControl
    {
        public LabeledTextBox()
        {
            InitializeComponent();
            this.MyHorizontalLabeledControl.Bind(HorizontalLabeledControl.LabelProperty, "Label", this);
            this.MyHorizontalLabeledControl.Bind(HorizontalLabeledControl.LabelWidthProperty, "LabelWidth", this);
            this.MyTextBox.Bind(TextBox.TextProperty, "Text", this, System.Windows.Data.BindingMode.TwoWay);

            this.GotFocus += delegate
            {
                this.MyTextBox.Focus();
            };

        }

        public void SetFocus()
        {
            this.MyTextBox.Focus();
        }

        #region Label

        /// <summary>
        /// Gets or sets the Label.
        /// </summary>
        public string Label
        {
            get { return (string)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for Label.
        /// </summary>
        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register("Label", typeof(string), typeof(LabeledTextBox), new UIPropertyMetadata("label"));

        #endregion

        #region LabelWidth

        /// <summary>
        /// Gets or sets the LabelWidth.
        /// </summary>
        public double LabelWidth
        {
            get { return (double)GetValue(LabelWidthProperty); }
            set { SetValue(LabelWidthProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for LabelWidth.
        /// </summary>
        public static readonly DependencyProperty LabelWidthProperty =
            DependencyProperty.Register("LabelWidth", typeof(double), typeof(LabeledTextBox), new UIPropertyMetadata(double.NaN));

        #endregion

        #region Text

        /// <summary>
        /// Gets or sets the Text.
        /// </summary>
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for Text.
        /// </summary>
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(LabeledTextBox), new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        #endregion
    }
}
